package com.gxuwz.icefrede.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxuwz.icefrede.entity.Delivery;
import com.gxuwz.icefrede.entity.User;
import com.gxuwz.icefrede.service.DeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/delivery")
public class DeliveryController {
    @Autowired
    private DeliveryService deliveryService;

    /**
     * 根据id获取配送信息
     *
     * @return 配送信息id
     */
    @RequestMapping("/get")
    public Long get(HttpSession session) {
        LambdaQueryWrapper<Delivery> wrapper = new LambdaQueryWrapper<>();
        User user = (User) session.getAttribute("user");
        if (user != null && user.getRole().equals("DELIVERY")) {
            wrapper.eq(Delivery::getUserId, user.getId());
            Delivery delivery = deliveryService.getOne(wrapper);
            if (delivery == null) {
                return null;
            }
            return delivery.getId();
        }else{
           return null;

        }
    }
}
